<!DOCTYPE html>
<html>
<head>
    <title>WebSocket Example</title>
</head>
<body>
<h1>WebSocket Chat Client</h1>
<script type="text/javascript">
    // 创建一个WebSocket实例
    var ws = new WebSocket("ws://localhost:8888/myWs/2");

    // 当WebSocket打开时触发
    ws.onopen = function(event) {
        console.log("WebSocket connected!");
    };

    // 当接收到服务器消息时触发
    ws.onmessage = function(event) {
        console.log("Received message: " + event.data);
    };

    // 当WebSocket关闭时触发
    ws.onclose = function(event) {
        console.log("WebSocket disconnected");
    };

    // 发送消息到服务器
    function sendMessage(message) {
        ws.send(message);
    }
</script>
</body>
</html>
